package com.huangc.cn.rainbow.controller;

import com.huangc.cn.rainbow.engine.DataTaskEngine;
import com.huangc.cn.rainbow.task.UploadTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author huangc
 */
@Slf4j
@RestController
@RequestMapping("/data")
public class DataTaskController {

    private DataTaskEngine taskEngine = DataTaskEngine.DataTaskEngineFactory.getInstance();

    @GetMapping(value = "/upload")
    public void upload(String start, String end) {
            LocalDate startDate = LocalDate.parse(start);
            LocalDate endDate = LocalDate.parse(end);
//
//        UploadTask task = new UploadTask(startDate.toString());
//        taskEngine.execute(task);

            while(!startDate.isAfter(endDate)) {
                UploadTask task = new UploadTask(startDate.toString());
                taskEngine.execute(task);
                startDate = startDate.plusDays(1);
            }
    }
}
